package com.open.thinks.todo.system.dao.impl;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.neodatis.odb.ODB;
import org.neodatis.odb.ODBFactory;

public class ODBProvider {

	private String fileName;

	private ODB instance = null;

	private final Lock lock = new ReentrantLock();

	public ODB getODB() {
		lock.lock();
		try {
			if (instance == null) {
				instance = ODBFactory.open(fileName);
			}
		} finally {
			lock.unlock();
		}
		return instance;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public void release() {
		if (instance != null) {
			instance.close();
		}
	}
}
